@extends('admin/user/layout')

@if($menu='user')@endif

@section('main')
    <div class="page-header clearfix">
        <h1 class="pull-left">用户管理</h1>
        <button class="btn btn-info btn-sm pull-right" data-toggle="modal" data-url="{{ url('admin/user/create') }}" data-target="#modal"><span class="glyphicon glyphicon-plus"></span> 添加新用户</button>
    </div>
    <form action="" class="well well-sm form-inline" method="get">
        <div class="form-group">
            <select name="search[keyword_type]" class="form-control">
                <option value="name" @if(Input::get('search')['keyword_type'] == 'name') selected @endif>用户名</option>
                <option value="email" @if(Input::get('search')['keyword_type'] == 'email') selected @endif>邮箱</option>
                <option value="mobile" @if(Input::get('search')['keyword_type'] == 'mobile') selected @endif>手机号</option>
            </select>
        </div>
        <div class="form-group">
            <input class="form-control" name="search[keywords]" type="text" placeholder="" value="{{ Input::get('search')['keywords'] }}">
        </div>
        <button class="btn btn-primary" type="submit">搜索</button>
    </form>
    <table class="table table-striped">
        <tr>
            <th>用户名</th>
            <th>Email/手机号</th>
            <th>注册时间</th>
            <th>最近登录</th>
            <th>操作</th>
        </tr>
        @forelse($list as $vo)
            <tr>
                <td>
                {{ $vo->name }}
                <br/>
                <span class="text-muted text-sm">
                @foreach($vo->roles as $role)
                    @if($role->name == 'admin')
                   <span class="label label-danger label-sm">{{ $role->display_name }}</span>
                    @else
                    <span class="label label-default">{{ $role->display_name  }}</span>
                    @endif
                @endforeach
                </span>
                </td>
                <td>
                    @if($vo->mobile)
                        <em class="glyphicon glyphicon-envelope"></em> {{ $vo->mobile}}
                    @else
                        <em class="glyphicon glyphicon-earphone"></em> {{ $vo->email}}
                    @endif
                    @if($vo->locked)<span class="label label-danger">禁</span>@endif
                </td>
                <td>
                    <span class="text-sm">{{ date('Y-m-d H:i:s',$vo->register_time) }}</span>
                    <br>
                    <span class="text-muted text-sm">
                    <a class="text-muted text-sm" href="http://www.baidu.com/s?wd={{ $vo->register_ip }}" target="_blank">{{ $vo->register_ip }}</a>
                  </span>
                    <span class="text-muted text-sm">{{ getIpName($vo->register_ip) }}</span>
                </td>
                <td>
                    <span class="text-sm">{{ date('Y-m-d H:i:s',$vo->login_time) }}</span>
                    <br>
                    <span class="text-muted text-sm">
                    <a class="text-muted text-sm" href="http://www.baidu.com/s?wd={{ $vo->login_ip }}" target="_blank">{{ $vo->login_ip }}</a>
                  </span>
                    <span class="text-muted text-sm">{{ getIpName($vo->login_ip) }}</span>
                </td>
                <td>
                    <div class="btn-group">
                          <a href="#modal" data-toggle="modal" data-url="{{ url('admin/user/'.$vo->id) }}" class="btn btn-default btn-sm">查看</a>
                          <a href="#" type="button" class="btn btn-default btn-sm dropdown-toggle" data-toggle="dropdown">
                            <span class="caret"></span>
                          </a>
                                <ul class="dropdown-menu">
                                        <li><a href="#modal" data-toggle="modal" data-url="{{ url('admin/user/assign_role',['id'=>$vo->id]) }}"><span class="glyphicon glyphicon-cog"></span>
                                        设置角色</a></li>
                                                        <li><a class="lock-user ajax-get" href="{{ url('admin/user/lock',['id'=>$vo->id,'lock'=>$vo->locked == 1 ? 0 : 1]) }}" >
                                                        @if($vo->locked == 1)
                                                        <span class="glyphicon glyphicon-ok-circle"></span> 解禁用户
                                                        @else
                                                        <span class="glyphicon glyphicon-ban-circle"></span> 封禁用户
                                                        @endif</a></li>

                                                      </ul>
                              </div>
                </td>
            </tr>
        @empty
            <tr>
                <td colspan="20">
                    <div class="empty">暂无页面记录</div>
                </td>
            </tr>
        @endforelse
    </table>
    <?php echo $list->appends(Request::all())->render(); ?>

@endsection